package com.hao.tool.extra.simple;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.hao.tool.extra.cloud.module.ali.entity.AlCosDTO;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.time.LocalDateTime;
import java.util.Scanner;

/**
 * 批量上传文件
 *
 * @author HaoZ on CMHK.gz
 * @date 2020-11-05 14:22
 */
public class FileBatchUploadTool {


    public static void main(String[] args) throws FileNotFoundException {
        FileBatchUploadTool fileBatchUploadTool = new FileBatchUploadTool();
        fileBatchUploadTool.execute();
    }

    public void execute() throws FileNotFoundException {
        String logPath = "HaoSimpleTool" + File.separator + "bchLog.log";

        Scanner scan = new Scanner(System.in);

        System.out.println("请输入：【cos上传的根目录】");
        String cosFilePath = scan.nextLine();
        System.out.println("请输入：【本地文件或文件夹名】");
        String filePath = scan.next();
        File file = new File(filePath);
        if (!file.exists()) {
            System.out.println("文件不存在！！！");
        }

        if (StringUtils.isNotBlank(cosFilePath)) {
            if (!cosFilePath.startsWith("/")) {
                cosFilePath = "/" + cosFilePath;
            }
        }
        AlCosDTO alCosDTO = new AlCosDTO();
        alCosDTO.setBucketName("ecip");
        alCosDTO.setCosPrefixUrl("http://e.lymtr.cn/");
        String yyyyMMdd = "fileupload"
                + "/" + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN)
                + cosFilePath;
        AliCosUploadUtil batchUploadUtil = new AliCosUploadUtil(filePath, logPath);

        batchUploadUtil.uploadDefDir(file, yyyyMMdd, alCosDTO, false);
    }


}
